package com.szcinda.controller.params;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.szcinda.controller.excelUtil.GsonUtil;
import com.szcinda.repository.ExchangeRate;
import com.szcinda.service.TypeStringUtils;
import com.szcinda.service.dto.zadOrder.ZadOrderDto;
import lombok.Data;

import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
public class QueryDto implements Serializable {

    // partExportByTypeQuery
    String currencyType;
    String type;
    String userId;
    String tableName;
    List<String> ids;
    List<String> exportFeeNames;
    String bankInfoId;
    String exportColumns;
    String rateListStr;
    List<ExchangeRate> rateList;
    List<String> feeNames;
    Map<String, String> fieldMap;
    String excelPath;
    String excelType;
    String api;
    String rate;// 汇率
    Map<String, String> ext = new HashMap<>();

    // exportByTypeQuery
    /*String preDepartureTimeStart;
    String preDepartureTimeEnd;
    String pickDateStart;
    String pickDateEnd;*/
    private LocalDate pickDateStart;
    private LocalDate pickDateEnd;
    private LocalDate actDepartureTimeStart;
    private LocalDate actDepartureTimeEnd;
    private LocalDate createTimeStart;
    private LocalDate createTimeEnd;
    private LocalDate receiveDateStart;
    private LocalDate receiveDateEnd;
    String carrierId;
    String clientId;
    private String orderNumber;
    private String bookNumber;
    private String carrierDeparturePort;
    private String originPlace;
    private String destPlace;
    private String userName;
    private String invoice;
    private String settlement;
    private String outInvoice;
    private String outSettlement;
    String currency;
    private String bookName;
    private String businessNumber;
    private LocalDate preDepartureTimeStart;
    private LocalDate preDepartureTimeEnd;
    private String organizationId;


    public static void main(String[] args) throws Exception {
        QueryDto dto = new QueryDto();
        dto.setType(TypeStringUtils.feeInType);
        dto.setUserId("1");
        dto.setIds(Arrays.asList("ZO221708391528140800", "ZO224120932355149824"));
        dto.setTableName("zadOrderReceivable");
        dto.setCurrencyType(TypeStringUtils.unTransfer);
        dto.setBankInfoId("BI221582884333555712");
        dto.setExportColumns("订单编号,所属机构,客户,订舱人,订舱号,业务类型,柜号,业务编号,计费方式,提货日期,提货地点,数量,柜型,班列日期,发车日期,起始站,目的站,出境口岸,报关方式,货物品类,货物品名,货物重量(KG),到达目的地时间,离开目的地时间,超期天数,创建人,运输费,仓储费,货柜处理");
        dto.setFeeNames(Arrays.asList("运输费", "仓储费", "货柜处理"));
        ObjectMapper objectMapper = new ObjectMapper();
        dto.setFieldMap(ZadOrderDto.getFieldMap());
        dto.setRateListStr("[]");
        dto.setExcelPath("D:\\upload\\excel.xlsx");
        dto.setApi("http://localhost:9045/api/zadOrder/partExportByTypeQuery");
        dto.getExt().put("invoiceNo", "test");
        dto.getExt().put("date", "test");
        dto.getExt().put("bankAccountName", "test");
        dto.getExt().put("rmbCompany", "test");
        dto.getExt().put("usdCompany", "test");
        dto.getExt().put("rmbBankName", "test");
        dto.getExt().put("usdBankName", "test");
        dto.getExt().put("rmbBankAccount", "test");
        dto.getExt().put("usdBankAccount", "test");
        System.out.println(GsonUtil.toJsonString(objectMapper.writeValueAsString(dto)));

        try {
            //这个方法是类似隐形开启了命令执行器，输入指令执行python脚本
            Process process = Runtime.getRuntime()
                    .exec("C:\\Users\\cindata-hrs\\AppData\\Local\\Programs\\Python\\Python37\\python.exe " + "E:\\PYTHON-PROJRCT\\XingDa-project\\ExcelHandle_bak20240410.py " + GsonUtil.toJsonString(objectMapper.writeValueAsString(dto)));
            //这种方式获取返回值的方式是需要用python打印输出，然后java去获取命令行的输出，在java返回
            InputStreamReader ir = new InputStreamReader(process.getInputStream());
            LineNumberReader input = new LineNumberReader(ir);
            String result = input.readLine();//中文的话这里可能会有乱码，可以尝试转一下不过问题不大
            input.close();
            ir.close();
            process.waitFor();
            System.out.println(result);
        } catch (Exception e) {
            System.out.println("调用python脚本并读取结果时出错：" + e.getMessage());
        }

        /*try {
            //这个方法是类似隐形开启了命令执行器，输入指令执行python脚本
            Process process = Runtime.getRuntime()
                    .exec("C:\\Users\\cindata-hrs\\AppData\\Local\\Programs\\Python\\Python37\\python.exe " +"E:\\PYTHON-PROJRCT\\XingDa-project\\testCreateFile.py");
            //这种方式获取返回值的方式是需要用python打印输出，然后java去获取命令行的输出，在java返回
            InputStreamReader ir = new InputStreamReader(process.getInputStream());
            LineNumberReader input = new LineNumberReader(ir);
            String result = input.readLine();//中文的话这里可能会有乱码，可以尝试转一下不过问题不大
            input.close();
            ir.close();
            process.waitFor();
            System.out.println(result);
        } catch (Exception e) {
            System.out.println("调用python脚本并读取结果时出错：" + e.getMessage());
        }*/
    }


}
